var loginValidator;
var editor;

var modelObject = {
	init:function(){
		//--表单验证 start--
		loginValidator = $("#configImageForm").validate
		({
			rules: {
				configValue: "required"
			},
			messages:{
				configValue:"请上传封面图片"
			},
			submitHandler:function(form){
				form.submit();
			}
		});
		//-- 表单验证 end --
		
		
	}
};

var kindEditors = {
	init: function(){
		//绑定修改图片按钮start
		KindEditor.ready(function(K) {
			var imgEditor = K.editor({
				uploadJson : '../../fileUpload',
		        fileManagerJson : '../../fileManage',
		        allowImageUpload : true,
		        allowFileManager : true
			});
			$('#image_upload').click(function() {
				imgEditor.loadPlugin('image', function() {
					imgEditor.plugin.imageDialog({
						imageUrl : $('#configValue').val(),
						clickFn : function(url, title, width, height, border, align) {
							$('#configValue').val(url);
							$('#img_display').attr('src',url);
							$('#img_display').show();
							$('#image_update').show();
							$('#image_upload').hide();
							imgEditor.hideDialog();
						}
					});
				});
			});
			$('#image_update').click(function() {
				imgEditor.loadPlugin('image', function() {
					imgEditor.plugin.imageDialog({
						imageUrl : $('#configValue').val(),
						clickFn : function(url, title, width, height, border, align) {
							$('#configValue').val(url);
							$('#img_display').attr('src',url);
							$('#img_display').show();
							$('#image_update').show();
							$('#image_upload').hide();
							imgEditor.hideDialog();
						}
					});
				});
			});
		});
		//绑定修改图片按钮end
		
		/* 输入框 KindEditor 配置、创建 START*/
		//关闭过滤模式，保留所有标签
		KindEditor.options.filterMode = false;
		editor = KindEditor.create('textarea[name="description"]',{
			 uploadJson : '../../fileUpload',
	         fileManagerJson : '../../fileManage',
	         allowImageUpload : true,
	         allowFileManager : true
		});
		/* 输入框 KindEditor 配置、创建  END*/
	}
};

$(document).ready(function(){
	kindEditors.init();
	modelObject.init();
	
	$("#reset").click(function(){
		$("#configValue").val("");
		$('#img_display').hide();
		$('#image_update').hide();
		$('#image_upload').show();
	});
});